﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using InnovTech.IO;
using System.IO;
using System.Security.Cryptography;
using Rhino.Mocks;
using System.Reflection;
using System.Linq.Expressions;

namespace Test.IO
{
    [TestClass]
    public class TestStreamExtension
    {
        [TestMethod]
        public void TestReset()
        {
            ICryptoTransform cTransform = MockRepository.GenerateStub<ICryptoTransform>();
            using (Stream stream = new MemoryStream())
            using (CryptoStream cStream = new CryptoStream(stream, cTransform, CryptoStreamMode.Read))
            {
                stream.WriteByte(1);
                stream.Flush();

                Assert.AreNotEqual(0, stream.Position);
                stream.Reset();
                Assert.AreEqual(0, stream.Position);

                // Uses CryptoStream, whose CanSeek property is alway false. In this case NO EXCEPTION.
                cStream.Reset();
            }
        }

        [TestMethod]
        public void TestSeek()
        {
            ICryptoTransform cTransform = MockRepository.GenerateStub<ICryptoTransform>();
            using (Stream stream = new MemoryStream())
            using (CryptoStream cStream = new CryptoStream(stream, cTransform, CryptoStreamMode.Read))
            {
                for (int i = 0; i < 10; i++)
                {
                    stream.WriteByte(1);
                    stream.Flush();
                }
                

                Assert.AreNotEqual(0, stream.Position);
                long newAccessPoint = stream.Position - 1;
                stream.Seek(newAccessPoint);
                Assert.AreEqual(newAccessPoint, stream.Position);

                // Uses CryptoStream, whose CanSeek property is alway false. In this case NO EXCEPTION.
                cStream.Reset();
            }
        }

       
    }
}
